/**
 * @param {number[]} candidates
 * @param {number} target
 * @return {number[][]}
 */
var combinationSum2 = function (candidates, target) {
  candidates.sort((a, b) => a - b)
  let count = 0
  const foo = (param) => {
    if (!exist(param)) {
      return 0
    }
    if (param == 0) {
      return 1
    } else if (param == 1 && exist(1)) {
      return 1
    } else {
      return foo(param - 1) * foo(1)
    }
  }
  const exist = (num) => {
    for (let i = 0; i < candidates.length; i++) {
      if (candidates[i] === num)
        return true
    }
    return false
  }
  for (let i = 0; i <= Math.floor(target / 2); i++) {
    count += foo(i) * foo(target - i)
  }

  return count
}
console.log(combinationSum2([10, 1, 2, 7, 6, 1, 5], 8))